﻿using System.Collections.Generic;
using System.Data;

namespace SlamCms.Data.Repositories
{
	public class UrlHandlerRepository : IUrlHandlerRepository
	{
		private readonly IDbConnection _dbConnection;

		public UrlHandlerRepository(IDbConnection dbConnection)
		{
			_dbConnection = dbConnection;
		}

		public IEnumerable<UrlHandler> GetAll()
		{
			var sql = @"select * from [dbo].[UrlHandler] with (nolock)";
			return _dbConnection.Query<UrlHandler>(sql, new {});
		}

		public UrlHandler Get(int urlHandlerId)
		{
			return _dbConnection.Get<UrlHandler>(urlHandlerId);
		}

		public void Save(UrlHandler urlHandler)
		{
			_dbConnection.Insert(urlHandler);
		}

		public void Remove(int urlHandlerId)
		{
			_dbConnection.Execute(@"delete from [dbo].[UrlHandler] where UrlHandlerId = @UrlHandlerId", new { urlHandlerId });
		}
	}
}
